package com.cm309.hospital.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.cm309.hospital.model.Patient;

public class PatientDao {
	public static MyDataSource mds = new MyDataSource();
	
	public Patient querySingle(String patient_id) {
		Patient patient = null;
		try {
			Connection conn = mds.getConnection();
			PreparedStatement ps = null;
			try {
				ps = conn.prepareStatement("SELECT * FROM Patient WHERE patient_id = ?");
				ps.setString(1, patient_id);
				ResultSet rs = ps.executeQuery();

				if (rs.next()) {
					patient = new Patient(rs.getString("patient_id"),
							rs.getString("patient_name"), rs.getString("id_card_num"),
							rs.getDate("date_of_birth"),rs.getString("sex"));
				}

			} finally {
				ps.close();
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return patient;
		
	}

}
